<template>
    <div>
        <h1>显示权益列表</h1>
        <table class="table">
            <thead>
                <tr>
                    <td>权益ID</td>
                    <td>权益名称</td>
                    <td>权益说明</td>
                    <td>状态</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody >
                <tr v-for="a in data">
                    <td>{{a.qid  }}</td>
                    <td>{{a.name  }}</td>
                    <td>{{a.shemo  }}</td>
                    <td>{{a.start?"启用":"禁用"  }}</td>
                    <td><input type="button" :value="a.start?'禁用':'启用' " @click="upsta(a.qid)">
                        <input type="button" value="删除" @click="Deletsta(a.qid)">
                        <input type="button" value="编辑" @click="UptQu(a.qid)">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>
<script setup lang="ts">
import {ref,onMounted} from "vue"
import axios from "axios";
import { useRouter } from "vue-router";
const router=useRouter();
const UptQu=(val:number)=>{
  router.push({path:"/UptView",query:{id:val}})
}
const data=ref([{
    "qid": 0,
  "name": "",
  "shemo": "",
  "start": true
}])
onMounted(()=>{
    Show();
})
const Show=()=>{
    axios.get("https://localhost:7083/api/Query/GetQuery").then(res=>{
        data.value=res.data
    })
}
const upsta=(id:any)=>{
    if(!confirm('确认修改吗')){
        return;
    }
    axios.get("https://localhost:7083/api/Query/UpStart",{params:{id:id}}).then(res=>{
    if(res.data>0){
        alert('修改成功');
        Show();
    }
    else{
        alert('修改失败');
    }
    })
}
const Deletsta=(ids:any)=>{
    if(!confirm('确认删除吗')){
        return;
    }
    axios.delete("https://localhost:7083/api/Query/DeleteQuery",{params:{id:ids}}).then(res=>{
    if(res.data>0){
        alert('删除成功');
        Show();
    }
    else{
        alert('删除失败');
    }
    })
}

</script>
<style scoped></style>
